home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
Tools
/
keycode
/
keycode.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-18
|
3KB
|
170 lines
/*
* code - a program to determine the numerical codes for keys on the
* keyboard.
*
* call:
* code
*
* instructions:
* Call code, and you will get the prompt ``code> ''
* enter the key and and you will see the numerical
* codes in decimal, octal and hexadecimal.
* Enter DEL twice to escape the program.
*
* (c) 1986 by Kim Chr. Madsen @ AmbraSoft A/S
* kimcm@olamb.UUCP or ..seismo!mcvax!diku!olamb!kimcm
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <termio.h>
#include <sys/ioctl.h>
#include "ascii.h"
struct termio tty, ntty;
main(argc, argv)
int argc;
char *argv[];
{
char *prompt = "keycode> ";
char c;
int pos;
int del=0;
printf("Hit DEL twice to exit.\n");
if (ioctl(0, TCGETA, &tty)) {
perror("ioctl");
exit(1);
}
ntty = tty;
ntty.c_iflag &= ~IXON;
ntty.c_iflag &= ~IXOFF;
ntty.c_lflag &= ~ISIG;
ntty.c_lflag &= ~ICANON;
ntty.c_lflag &= ~ECHO;
ntty.c_oflag &= ~OPOST;
ntty.c_cc[VTIME] = 30;
ntty.c_cc[VMIN] = 1;
ioctl(0, TCSETA, &ntty);
printf(prompt);
pos=3;
for (;;) {
c=getchar();
switch (c) {
case NUL :
printf("<NUL>");
break;
case SOH :
printf("<SOH>");
break;
case STX :
printf("<STX>");
break;
case ETX :
printf("<ETX>");
break;
case EOT :
printf("<EOT>");
break;
case ENQ :
printf("<ENQ>");
break;
case ACK :
printf("<ACK>");
break;
case BEL :
printf("<BEL>");
break;
case BS :
printf("<BS> ");
break;
case HT :
printf("<HT> ");
break;
case LF :
printf("<LF> ");
break;
case VT :
printf("<VT> ");
break;
case FF :
printf("<FF> ");
break;
case CR :
printf("<CR> ");
break;
case SO :
printf("<SO> ");
break;
case SI :
printf("<SI> ");
break;
case DLE :
printf("<DLE>");
break;
case DC1 :
printf("<DC1>");
break;
case DC2 :
printf("<DC2>");
break;
case DC3 :
printf("<DC3>");
break;
case DC4 :
printf("<DC4>");
break;
case NAK :
printf("<NAK>");
break;
case SYN :
printf("<SYN>");
break;
case ETB :
printf("<ETB>");
break;
case CAN :
printf("<CAN>");
break;
case EM :
printf("<EM> ");
break;
case SUB :
printf("<SUB>");
break;
case ESC :
printf("<ESC>");
break;
case FS :
printf("<FS> ");
break;
case GS :
printf("<GS> ");
break;
case RS :
printf("<RS> ");
break;
case US :
printf("<US> ");
break;
case SP :
printf("<SP> ");
break;
case DEL :
if (del) goto end;
del++;
printf("<DEL>");
break;
default :
printf("%c ",c);
break;
}
printf(" %4d 0%-4o 0x%-4x\n\r%s",c,c,c,prompt);
if (c != DEL) del=0;
}
end: printf("\n\r");
ioctl(0, TCSETA, &tty);
}